﻿using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Data.Objects;
using System.Data.Objects.DataClasses;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using Defero.Core;
using Defero.Core.DataTransferObjects;
using Defero.Core.Repositories;
using Defero.Infrastucture.Persistence.BugTracker;

namespace Defero.Infrastucture.Repositories
{
    public partial class BugTrackerRepository : 
                Repository<BugTrackerContext>, 
                IBugTrackerRepository, 
                IBugTrackerQueryRepository
    {
        /// <summary>
        /// Constructor default.
        /// </summary>
        public BugTrackerRepository(DbConnection connection) : base(connection){}
        /// <summary>
        /// Regresa una lista con los bugs asignados a determinado usuario.
        /// </summary>
        /// <param name="userId">Id del usuario asignado.</param>
        /// <param name="status">Status del bug.</param>
        public IEnumerable<BugHeader> GetBugs(Guid userId, 
            params Core.Entities.BugStatus[] status) 
        {
            return Context.Bugs
                .Where(AssignedUserIs(userId))
                .Where(CurrentStatusInRange(status))
                .Select(BugSelector);
        }

    }
}
